import { createApp } from 'vue'
import { createPinia } from 'pinia'
import './style.css'
import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import wxService from './utils/wxService'

const app = createApp(App)
const pinia = createPinia()

app.use(pinia)

// 使用 Element Plus
app.use(ElementPlus)

// 添加屏幕宽度检测
// const checkScreenWidth = () => {
//     const currentHost = window.location.origin
//     const currentPath = window.location.pathname
//     const isMobilePath = currentPath.includes('/mobile')
//     const isSmallScreen = window.innerWidth < 768

//     // 小屏幕但不在移动端页面，跳转到移动端
//     if (isSmallScreen && !isMobilePath) {
//         window.location.href = `${currentHost}/mobile/login`
//     }
//     // 大屏幕但在移动端页面，跳转到PC端
//     else if (!isSmallScreen && isMobilePath) {
//         window.location.href = `${currentHost}/home`
//     }
// }

// checkScreenWidth()
// 添加防抖处理
let resizeTimer
window.addEventListener('resize', () => {
    clearTimeout(resizeTimer)
    // resizeTimer = setTimeout(checkScreenWidth, 100)
})


// 注册所有图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

app.use(router)
app.mount('#app')

// 在 app 创建后初始化微信服务
wxService.init()
